package edu.zhang.front.controller;

import java.io.IOException;
import java.lang.annotation.Target;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.zhang.dao.CustomerDAO;
import edu.zhang.po.Customer;

@WebServlet("/customer/CustomerLoginController")
public class CustomerLoginController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private CustomerDAO customerDAO = new CustomerDAO();
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		
		//System.out.println(account);
		
		Customer customer = customerDAO.login(account, password);
		
		request.getSession().setAttribute("customer", customer);
		
		if(customer != null) {
			request.getRequestDispatcher("/customer/HomepageMenu").forward(request, response);
		}else {
			response.sendRedirect("login.jsp");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		this.doGet(request, response);
	}

}
